Type.registerNamespace('ModWatch');

ModWatch.OnAnchorClickModAlertBehavior = function(element) { 
    ModWatch.OnAnchorClickModAlertBehavior.initializeBase(this, [element]);

	// Click handler for the target control.
	this._clickHandler = null;

	this._href = null;
}

ModWatch.OnAnchorClickModAlertBehavior.prototype = {

	_onClick : function(e)
	{
		if (this.get_element() && !this.get_element().disabled)
		{
			if (this.verifyChanges())
			{
				if (typeof(this._href) == 'function')
					this._href();
				else
					window.location = this._href;
			}
		}
	},

	initialize : function()
	{
		ModWatch.OnAnchorClickModAlertBehavior.callBaseMethod(this, 'initialize');
		var element = this.get_element();

		this._href = element.getAttribute("href");
		element.setAttribute("href", "javascript:void(0);");

		// Attach the handler
		this._clickHandler = Function.createDelegate(this, this._onClick);
		$addHandler(element, "click", this._clickHandler);
	},

	dispose : function()
	{
		if (this._clickHandler)
		{
			$removeHandler(this.get_element(), "click", this._clickHandler);
			this._clickHandler = null;
		}

		if (this._oldScript)
		{
			this.get_element().setAttribute("onclick", this._oldScript);
			this._oldScript = null;
		}

		this.get_element().setAttribute("href", this._href);

		ModWatch.OnAnchorClickModAlertBehavior.callBaseMethod(this, 'dispose');
	}

}

ModWatch.OnAnchorClickModAlertBehavior.registerClass('ModWatch.OnAnchorClickModAlertBehavior', ModWatch.ModAlertBehaviorBase);


if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
